package com.educate.book.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.book.model.bo.ChildBookBO;
import com.educate.book.rpc.api.ChildBookService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("childBook")
public class ChildBookController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private ChildBookService childBookService;

    @PostMapping(value = "/create")
    public R create(@RequestBody ChildBookBO bo) {
        childBookService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody ChildBookBO bo) {
        childBookService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{childBookId}")
    public R delete(@PathVariable String childBookId) {
        childBookService.delete(childBookId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{childBookId}")
    public R<ChildBookBO> detail(@PathVariable String childBookId) {
        ChildBookBO bo = childBookService.detail(childBookId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<ChildBookBO> detail(@RequestBody ChildBookBO bo) {
        ChildBookBO detail = childBookService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<ChildBookBO> update(@RequestBody ChildBookBO bo) {
        childBookService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<ChildBookBO>> query(@RequestBody ChildBookBO bo) {
        Page<ChildBookBO> result = childBookService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<ChildBookBO>> list(@RequestBody ChildBookBO bo) {
        List<ChildBookBO> result = childBookService.list(bo);
        return R.ok(result);
    }

}
